<?php $this->_extends('_layouts/report_layout'); ?>
<?php $this->_block('title');
	switch($reporttype){
		case '0': $pagetitle = 'Media Performance';				break;
		case '1': $pagetitle = 'Site Performance';				break;
		case '2': $pagetitle = 'Game Performance';				break;
		case '3': $pagetitle = 'Advertiser Performance';		break;
		case '4': $pagetitle = 'Viral Performance';				break;
		case '5': $pagetitle = 'Email Performance';				break;
		case '6': $pagetitle = 'Offers Of Week Performance';	break;
		case '7': $pagetitle = 'Bluebar Offers Performance';	break;
		case '8': $pagetitle = 'Optin Performance';				break;
		case '9': $pagetitle = 'Banner Offers Performance';		break;
		case '10': $pagetitle = 'DailyDeals Offers Performance';		break;
	}
	echo $pagetitle;
$this->_endblock(); ?>

<?php $this->_block('contents'); ?>
		<div id="content" class="box">
			<h1><?php echo $pagetitle; ?></h1>
            <form id="form1" method="get" action="<?php echo url('report/index'); ?>">
            	<select id="reporttype" name="reporttype">
                   	<option disabled="disabled">---Publisher report---</option>
					<option value="0" <?php echo (isset($reporttype) && $reporttype=="0") ? 'selected="selected"' : '';?>>Media Performance Report</option>
					<option value="1" <?php echo (isset($reporttype) && $reporttype=="1") ? 'selected="selected"' : '';?>>Site Performance Report</option>
					<option value="2" <?php echo (isset($reporttype) && $reporttype=="2") ? 'selected="selected"' : '';?>>Game Performance Report</option>
					<option value="3" <?php echo (isset($reporttype) && $reporttype=="3") ? 'selected="selected"' : '';?>>Advertiser Performance Report</option>
					<option value="4" <?php echo (isset($reporttype) && $reporttype=="4") ? 'selected="selected"' : '';?>>Viral Performance Report</option>
					<option value="5" <?php echo (isset($reporttype) && $reporttype=="5") ? 'selected="selected"' : '';?>>Email Performance Report</option>
					<option value="6" <?php echo (isset($reporttype) && $reporttype=="6") ? 'selected="selected"' : '';?>>Offers Of Week Performance Report</option>
					<option value="7" <?php echo (isset($reporttype) && $reporttype=="7") ? 'selected="selected"' : '';?>>Bluebar Offers Performance Report</option>
					<option value="8" <?php echo (isset($reporttype) && $reporttype=="8") ? 'selected="selected"' : '';?>>Optin Performance Report</option>
					<option value="9" <?php echo (isset($reporttype) && $reporttype=="9") ? 'selected="selected"' : '';?>>Banner Offers Performance Report</option>
					<option value="10" <?php echo (isset($reporttype) && $reporttype=="10") ? 'selected="selected"' : '';?>>DailyDeals Offers Performance Report</option>
				</select>
                <script type="text/javascript">
					$("#reporttype").change(function(){
						if($("#reporttype").val()==0 || $("#reporttype").val()==1){
							for(var i=0; i<=6; i++){
								$("#displaycol" + i).attr({disabled:false, style:"display:inline"});
								$("#displaycol" + i + "text").attr("style", "display:inline");
							}
						}else{
							for(var i=0; i<=6; i++){
								$("#displaycol" + i).attr({disabled:true, style:"display:none"});
								$("#displaycol" + i + "text").attr("style", "display:none");
							}
						}
						if($("#reporttype").val()==1 || $("#reporttype").val()==4|| $("#reporttype").val()==5){
							$("#displaycol7").attr({disabled:false, style:"display:inline"});
							$("#displaycol7text").attr("style", "display:inline");
						}else{
							$("#displaycol7").attr({disabled:true, style:"display:none"});
							$("#displaycol7text").attr("style", "display:none");
						}
						if($("#reporttype").val()==8){
							for(var i=2; i<=4; i++){
								$("#displaycol" + i).attr({disabled:false, style:"display:inline"});
								$("#displaycol" + i + "text").attr("style", "display:inline");
							}
						}
						if($("#reporttype").val()==5 || $("#reporttype").val()==6){
							$('#interval').val(1);
						}
					});
				</script>
              	<select id="interval" name="interval">
                   	<option disabled="disabled">---interval---</option>
                   	<?php if($reporttype != '3' && $reporttype != '5'): ?>
						<option value="0" <?php echo (isset($interval) && $interval=="0") ? 'selected="selected"' : '';?>>Hourly</option>
					<?php endif; ?>
					<option value="1" <?php echo (isset($interval) && $interval=="1") ? 'selected="selected"' : '';?>>Daily</option>
					<option value="2" <?php echo (isset($interval) && $interval=="2") ? 'selected="selected"' : '';?>>Weekly</option>
              		<option value="3" <?php echo (isset($interval) && $interval=="3") ? 'selected="selected"' : '';?>>Monthly</option>
				</select>
               	<select id="duration" name="duration">
                 	<option disabled="disabled">---Duration---</option>
					<option value="0" <?php echo (isset($duration) && $duration=="0") ? 'selected="selected"' : '';?>>Today</option>
                  	<option value="1" <?php echo (isset($duration) && $duration=="1") ? 'selected="selected"' : '';?>>Yesterday</option>
                  	<option value="2" <?php echo (isset($duration) && $duration=="2") ? 'selected="selected"' : '';?>>Last 7 Days</option>
                   	<option value="3" <?php echo (isset($duration) && $duration=="3") ? 'selected="selected"' : '';?>>Month To Date</option>
                 	<option value="4" <?php echo (isset($duration) && $duration=="4") ? 'selected="selected"' : '';?>>Custom Date Range</option>
				</select>
                <script type="text/javascript">
					$("#duration").change(function(){
						if($("#duration").val()==4){
							$("#customdaterange").slideDown();	
						}else{
							$("#customdaterange").slideUp();
						}
					});
				</script>
              	<span id="customdaterange" <?php echo (isset($duration) && $duration=="4") ? '' : 'style="display:none;"';?> >
                  	<span>From</span><input type="text" value="<?php echo (is_array($customrangedate)) ? $customrangedate['start'] : '' ?>" id="startdate" name="startdate" class="myDatePickerClass" readonly="readonly" />
                   	<span>To</span><input type="text" value="<?php echo (is_array($customrangedate)) ? $customrangedate['end'] : '' ?>" id="enddate" name="enddate" class="myDatePickerClass" readonly="readonly" />
                   	<script type="text/javascript">
                       	$(".myDatePickerClass").datepicker({
                           	dateFormat:'yy-mm-dd',
                           	changeYear: true,
                           	changeMonth: true,
                        	showMonthAfterYear: true,
                    	})
                	</script>
                </span>
                <input type="submit" name="submit" value="Generate Report" />
                <input type="submit" name="submit" value="Export Report Csv" />
                <div>
					<?php //if($reporttype == '0' || $reporttype == '1'): ?>
	               		<input type="checkbox" id="displaycol0" name="displaycol[0]" value="0" <?php echo (isset($displayCols[0])) ? 'checked="true"' : ''; ?> <?php echo (isset($reporttype) && ($reporttype=="0" || $reporttype=="1")) ? '' : 'disabled'.' style="display:none;"'; ?> /><label id="displaycol0text" <?php echo (isset($reporttype) && ($reporttype=="0" || $reporttype=="1")) ? '' : 'style="display:none;"'; ?> for="displaycol0">Buy Type</label>
	                    <input type="checkbox" id="displaycol1" name="displaycol[1]" value="1" <?php echo (isset($displayCols[1])) ? 'checked="true"' : ''; ?> <?php echo (isset($reporttype) && ($reporttype=="0" || $reporttype=="1")) ? '' : 'disabled'.' style="display:none;"'; ?> /><label id="displaycol1text" <?php echo (isset($reporttype) && ($reporttype=="0" || $reporttype=="1")) ? '' : 'style="display:none;"'; ?> for="displaycol1">Media Type</label>
	                    <input type="checkbox" id="displaycol2" name="displaycol[2]" value="2" <?php echo (isset($displayCols[2])) ? 'checked="true"' : ''; ?> <?php echo (isset($reporttype) && ($reporttype=="0" || $reporttype=="1" || $reporttype=="8")) ? '' : 'disabled'.' style="display:none;"'; ?> /><label id="displaycol2text" <?php echo (isset($reporttype) && ($reporttype=="0" || $reporttype=="1" || $reporttype=="8")) ? '' : 'style="display:none;"'; ?> for="displaycol2">Publisher</label>
	                    <input type="checkbox" id="displaycol3" name="displaycol[3]" value="3" <?php echo (isset($displayCols[3])) ? 'checked="true"' : ''; ?> <?php echo (isset($reporttype) && ($reporttype=="0" || $reporttype=="1" || $reporttype=="8")) ? '' : 'disabled'.' style="display:none;"'; ?> /><label id="displaycol3text" <?php echo (isset($reporttype) && ($reporttype=="0" || $reporttype=="1" || $reporttype=="8")) ? '' : 'style="display:none;"'; ?> for="displaycol3">Placement</label>
	                    <input type="checkbox" id="displaycol4" name="displaycol[4]" value="4" <?php echo (isset($displayCols[4])) ? 'checked="true"' : ''; ?> <?php echo (isset($reporttype) && ($reporttype=="0" || $reporttype=="1" || $reporttype=="8")) ? '' : 'disabled'.' style="display:none;"'; ?> /><label id="displaycol4text" <?php echo (isset($reporttype) && ($reporttype=="0" || $reporttype=="1" || $reporttype=="8")) ? '' : 'style="display:none;"'; ?> for="displaycol4">Campaign</label>
	                    <input type="checkbox" id="displaycol5" name="displaycol[5]" value="5" <?php echo (isset($displayCols[5])) ? 'checked="true"' : ''; ?> <?php echo (isset($reporttype) && ($reporttype=="0" || $reporttype=="1")) ? '' : 'disabled'.' style="display:none;"'; ?> /><label id="displaycol5text" <?php echo (isset($reporttype) && ($reporttype=="0" || $reporttype=="1")) ? '' : 'style="display:none;"'; ?> for="displaycol5">Creative</label>
	                    <input type="checkbox" id="displaycol6" name="displaycol[6]" value="6" <?php echo (isset($displayCols[6])) ? 'checked="true"' : ''; ?> <?php echo (isset($reporttype) && ($reporttype=="0" || $reporttype=="1")) ? '' : 'disabled'.' style="display:none;"'; ?> /><label id="displaycol6text" <?php echo (isset($reporttype) && ($reporttype=="0" || $reporttype=="1")) ? '' : 'style="display:none;"'; ?> for="displaycol6">Monetization</label>
	                <?php //endif; ?>
	                <?php //if($reporttype == '1' || $reporttype == '4'): ?>
	                    <input type="checkbox" id="displaycol7" name="displaycol[7]" value="7" <?php echo (isset($displayCols[7])) ? 'checked="true"' : ''; ?> <?php echo (isset($reporttype) && ($reporttype=="1" || $reporttype=="4" || $reporttype=="5")) ? '' : 'disabled'.' style="display:none;"'; ?> /><label id="displaycol7text" <?php echo (isset($reporttype) && ($reporttype=="1" || $reporttype=="4" || $reporttype=="5")) ? '' : 'style="display:none;"'; ?> for="displaycol7">Site</label>
					<?php //endif; ?>
              	</div>
            </form>
            
            <?php if(isset($reporttype) && $reporttype=="0"):
				$this->_element('mediareport');
				$this->_element('addpixel');
			elseif(isset($reporttype) && $reporttype=="1"):
            	$this->_element('sitereport');
            elseif(isset($reporttype) && $reporttype=="2"):
            	$this->_element('gamereport');
            elseif(isset($reporttype) && $reporttype=="3"):
            	$this->_element('adreport');
            elseif(isset($reporttype) && $reporttype=="4"):
            	$this->_element('sharereport');
            elseif(isset($reporttype) && $reporttype=="5"):
            	$this->_element('emailreport');
            elseif(isset($reporttype) && $reporttype=="6"):
            	$this->_element('offerofweekreport');
            elseif(isset($reporttype) && $reporttype=="7"):
            	$this->_element('bluebarofferreport');
            elseif(isset($reporttype) && $reporttype=="8"):
            	$this->_element('optinreport');
            elseif(isset($reporttype) && $reporttype=="9"):
            	$this->_element('bannerofferreport');
            elseif(isset($reporttype) && $reporttype=="10"):
            	$this->_element('dailydealsofferreport');
            endif; ?>
		</div>
<script type="text/javascript" src="<?php echo JS_DIR; ?>jquery.metadata.js"></script>
<script type="text/javascript">

$('.close').click(function(event){
    event.stopPropagation(); 
    var width = $('#wrapper').width() - $(this).parent().width();
	var currentclass = $(this).parent().attr('class');
	var temp = currentclass.split(' ');
	var filterClass = temp[0];
	$('.' + filterClass).hide();
	if (width > 1680) {
		$('#wrapper').width(width);
	}
	else {
		$('#wrapper').width(1680);
	}
	
});

$(function(){
	var width = 450;
	var len = $('th').filter(':visible').length;
	$('#wrapper').width(450 + len * 120);
});
</script>
<center>Max Memory Usage: <?php echo memory_get_peak_usage(true) / (1000 * 1000);?> M</center>     
<?php $this->_endblock(); ?>